<?php

class Settings extends CI_Model {
    
    function get_settings($username) {
        $user = $this->mongo_db->get_where('community', array('username' => $username));
        return $user;
    }

    function update_settings($username,$data) {
        $this->mongo_db->where('username' , $username);
        $query = $this->mongo_db->set($data)->update('community');
        return $query;
    }
    function validate_settings(){
        
        $this->mongo_db->where('username', $this->input->post('username'));
        $this->mongo_db->where('email', md5($this->input->post('email_adress')));
        $query = $this->mongo_db->get('community');
        if (empty($query[0])) {
            return true;
        }
    }
    function update_password($username){
        $this->mongo_db->where('username' , $username);
        $query = $this->mongo_db->set(array("password" => md5($this->input->post('newPassword'))))->update('community');
    }
    function validatePass(){
        if($this->input->post('newPassword') === $this->input->post('PasswordConf')){
            return true;
        }
    }
    function SureRemoveDir($dir, $DeleteMe) {
    if(!$dh = @opendir($dir)) return;
    while (false !== ($obj = readdir($dh))) {
        if($obj=='.' || $obj=='..') continue;
        if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
    }

    closedir($dh);
    if ($DeleteMe){
        @rmdir($dir);
    }
}

}